import observe from "./observe";
import Dep from "./Dep";
export default function definedReactive(data, key, value) {
  if (arguments.length == 2) {
    value = data[key];
  }
  let dep = new Dep();
  var childOb = observe(value);

  Object.defineProperty(data, key, {
    get() {
      if (Dep.target) {
        dep.depend(value);
        if (childOb) {
          childOb.dep.depend();
        }
      }

      return value;
    },
    set(newValue) {
      if (newValue != value) {
        value = newValue;
        console.log(value, "vae");
        dep.notify();
        observe(value);
      }
    },
  });
}
